namespace SharpTalk.Core.Services.ServiceAgents
{
    using System;
    using System.ServiceModel;
    using Contracts.Server;
    using Requests;
    using Responses;

    /// <summary>
    /// 
    /// </summary>
    public sealed class MessageServiceAgent:
        ClientBase<IMessageServices>, IMessageServices
    {
        public MessageServiceAgent(string endpointConfigurationName) 
            : base(endpointConfigurationName)
        {
        }

        public MessageServiceAgent(string endpointConfigurationName, EndpointAddress remoteAddress) 
            : base(endpointConfigurationName, remoteAddress)
        {
        }

        public IAsyncResult BeginSendMessage(MessageSendRequest request, AsyncCallback callback, object state)
        {
            return base.Channel.BeginSendMessage(request, callback, state);
        }
        public MessageSendResponse EndSendMessage(IAsyncResult result)
        {
            try
            {
                return base.Channel.EndSendMessage(result);
            }
            catch (Exception exp)
            {
                return new MessageSendResponse(){ Error = new ErrorDetails(exp) };
            }
        }
    }
}